import { resources, SpriteFrame } from 'cc'
import { Singleton } from '../Base/Singleton'

export default class ResourceManager extends Singleton {
  static get Instance() {
    return super.getInstance<ResourceManager>()
  }

  // 批量加载文件夹path下面的所有资源
  loadDir(path: string, type: typeof SpriteFrame = SpriteFrame) {
    return new Promise<SpriteFrame[]>((resolve, reject) => {
      resources.loadDir(path, type, (err, spriteFrames) => {
        if (err) {
          reject(err)
        } else {
          resolve(spriteFrames)
        }
      })
    })
  }
}
